import request from '@/utils/request';
import {UserInfoType, UserAddressType} from '@/type/user';
import authService from '@/utils/authService';

// 用户登录
export const login = (data: { username?: string, phone?: string, email?: string, password: string }) => {
  return request.post('/accounts/login', data);
}

// 刷新token
export const refreshToken = () => {
  return request.post('/accounts/refresh', {});
}

// 获取用户信息
export const getUserInfo = () => {
  return request.get('/users/info');
}

// 更新用户信息
export const updateUserInfo = (data: UserInfoType) => {
  return request.put('/users/update', data);
}


// 获取订单列表
export const getOrders = (status: number, page: number, size: number) => {
  return request.get('/profile/orders', { params: { status, page, size } });
}

// 获取订单详情
export const getOrderDetail = (id: number) => {
  return request.get(`/profile/orders/${id}`);
}

// 获取地址列表
export const getAddresses = () => {
  return request.get('/address/list');
}

// 添加地址
export const saveAddress = (data: UserAddressType) => {
  return request.post('/address/save', data);
}

// 修改地址
export const updateAddress = (data: UserAddressType) => {
  return request.post('/address/update', data);
}

// 删除地址
export const deleteAddress = (id: number) => {
  return request.delete(`/address/${id}`);
}

// 获取所有省份数据
export const getProvinces = () => {
  return request.get('/city/provinces');
}

// 根据省份id获取城市数据
export const getCities = (provinceId: number) => {
  return request.get(`/city/cities/${provinceId}`);
}

// 根据城市id获取区县数据
export const getdistricts = (cityId: number) => {
  return request.get(`/city/districts/${cityId}`);
}